To create a Universal application in Visual Studio, complete the following steps:
- From the File menu in Microsoft Visual Studio, select New | Project. The New Project dialog box opens.
- Select the .NET Framework 4.5 from the dropdown listbox.
- Expand a Templates node in the left pane. For ComponentOne Studio projects, you can use Visual C# or Visual Basic.
- Under the Visual C# or Visual Basic language node, expand the Store Apps node and select Universal Apps. The list of Universal Apps templates will now appear in the center pane.
- Select the Blank App (Universal Apps) template.
- Give your project a name and click OK. The new solution will include three projects as shown in the following image:
The Windows project contains content exclusive to the Windows application.
The Windows Phone project contains content exclusive to the Windows Phone application.
The Shared project contains content that can be shared by all projects. The contents of the Shared project are automatically available to both the Windows and Windows Phone application projects.
Once you build your solution, Microsoft Visual Studio builds a Windows Phone Store application and a Windows Store application. There is no build output from the Shared project.
- Right-click the Shared project node, select Add | New Item. The Add New Item dialog box opens.
- Select the User Control template.
- Give your User Control a name and click OK. The shared project will now include content that can be referenced in all projects.
- In the Windows App project, open the MainPage.xaml.
- Between the <Grid> tags, enter <local:NameOfYourUserControl />. Notice the “local” namespace is automatically declared at the top of MainPage.xaml.
- Repeat step 10 for the Windows Phone project.
You’ve now shared a UserControl between both projects. You can add any ComponentOne controls to your shared User Controls and Pages and reuse code and XAML.
- Press F5 to run your solution; the project that runs is the project that is selected as the startup project.